home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1108 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  88 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: jah@cais.cais.com (John A Hughes)
  3. Newsgroups: comp.std.c++,comp.lang.c++
  4. Subject: Kind of Annoying
  5. Followup-To: comp.std.c++
  6. Date: 16 Apr 1996 13:13:07 PDT
  7. Organization: Capital Area Internet Service info@cais.com 703-448-4470
  8. Approved: austern@isolde.mti.sgi.com
  9. Message-ID: <4kjpfq$r3k@news2.cais.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 11 Apr 1996 20:19:06 GMT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMXP/VEy4NqrwXLNJAQFuPwH/Q6o/SSJmxb3DnTkvRs+DWmODj7n73rf4
  14.     U1EVzDIFqMvYpK9UBf/rd9Dntmc3c+ibJpSGKdBUNliSJOElRBE6zQ==
  15.     =Y+iN
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. [Moderator's note: This article is crossposted between comp.std.c++
  19. and comp.lang.c++, and followups have been set to comp.std.c++.  mha]
  20.  
  21. The following doesn't compile, because the calls to foo look ambiguous
  22. to the compiler:
  23.  
  24. template<class T>
  25. class Goo {
  26. public:
  27.     void foo(T *) {}
  28. };
  29.  
  30. class A {
  31. };
  32.  
  33. class B {
  34. };
  35.  
  36. class C : public Goo<A>, public Goo<B> {
  37. };
  38.  
  39. main() {
  40.     A a;
  41.     B b;
  42.     C c;
  43.     c.foo(&a);
  44.     c.foo(&b);
  45. }
  46.     
  47. Why is this? Why doesn't the mechanism that checks for which function to call
  48. look at the function signature instead of just the name? I presume this is
  49. related to the following:
  50.  
  51. class A {
  52. public:
  53.     void goo(A*) {}
  54. };
  55.  
  56. class B : public A {
  57. public:
  58.     void goo(B*) {}
  59. };
  60.  
  61. class C : public B {
  62. };
  63.  
  64. main() {
  65.    A a;
  66.    B b;
  67.    C c;
  68.    c.goo(&a);
  69.    c.goo(&b);
  70. }
  71.  
  72. which won't compile because B::goo hides A::goo (even though again they
  73. have different signatures). What's the interest of a having function hide
  74. another with a totally different prototype simply because their names match?
  75. Of course I can make these things compile by explicitly disambiguating in each 
  76. case, but it's annoying and I can't think of any benefit to this behavior. Why 
  77. does it work this way?
  78.  
  79.  
  80. jah
  81. ---
  82. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  83.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  84.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  85.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  86.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  87. ]
  88.